<!-- cpuresouce.vue -->

<template>
  <div>
    <el-table stripe border :data="tableData" style="width: 100%; margin-top: 15px">
      <el-table-column label="序号" width="60" type="index" :index="(index) => (index + 1) + (pageNum - 1) * pageSize">
      </el-table-column>
      <el-table-column label="所在分区" prop="PrimArea" width="150" align="left" show-overflow-tooltip>
        <template slot-scope="{ row }">
          <span>{{ row.PrimArea }} / {{ row.SecondArea }}</span>
        </template>
      </el-table-column>
      <el-table-column label="所在校区" show-overflow-tooltip prop="SchoolName" align="left">
        <template slot-scope="{ row }">
          <span>{{ row.SchoolName }}({{ row.SchoolID }})</span>
        </template>
      </el-table-column>
      <el-table-column label="资产名称" show-overflow-tooltip prop="DeviceName" align="left">
        <template slot-scope="{ row }">
          <span>{{ row.DeviceName }}({{ row.DeviceID }})</span>
        </template>
      </el-table-column>
      <el-table-column label="采集时间" show-overflow-tooltip prop="TransTime" align="left"></el-table-column>
      <el-table-column label="使用率" show-overflow-tooltip prop="Percent" width="320px" align="left">
        <template slot-scope="{ row }">
          <el-progress :stroke-width="10" :percentage="row.Percent"></el-progress>
        </template> 
      </el-table-column>
      <el-table-column label="操作" show-overflow-tooltip width="120px" align="left" fixed="right">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="changeModel(scope.row)">最近曲线</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageNum"
      :page-size="pageSize"
      background
      layout="total, prev, pager, sizes, next, jumper"
      :total="total"
    ></el-pagination>
  </div>
</template>

<script>
export default {
  props: {
    tableData: {
      type: Array,
      default: () => [],
    },
    pageNum: {
      type: Number,
      default: 1,
    },
    pageSize: {
      type: Number,
      default: 10,
    },
    total: {
      type: Number,
      default: 0,
    },
  },
  data(){
    return {
      logDialog: false,
    }
  },
  methods: {
    async changeModel(row){
      const data = {
        Filter:{
          DeviceID: row.DeviceID
        }
      }
      const res = await connrequest('GetDeviceHistoryPerfStatus', data)
      let downByte = []
      res.Data.map(item => {
        downByte.push((item.Used / item.Total) * 100)
      })
      this.lineData = {downByte}
      this.logDialog = true
    },
    handleSizeChange(pageSize){
      this.pageSize = pageSize
      this.pageNum = 1
      this.GetEventLog({...this.searchobj, StartTime: this.searchobj?.StartTime || this.searchform.timeRange?.[0] ||  '', EndTime: this.searchobj?.EndTime || this.searchform.timeRange?.[1] ||  ''})
    },
    handleCurrentChange( pageNum ){
      this.pageNum = pageNum
      this.GetEventLog({...this.searchobj, StartTime: this.searchobj?.StartTime || this.searchform.timeRange?.[0] ||  '', EndTime: this.searchobj?.EndTime || this.searchform.timeRange?.[1] ||  ''})
    },
  },
};
</script>

<style scoped>
/* Add scoped styles if needed */
</style>
